import org.w3c.dom.css.Rect;

import java.util.Locale;

public class extends_demo {
    public static void main(String[] args) {
        Student s = new Student("Xiao Ming", 12, 89);
        Persons persons=new Student();//向上转型
        Persons student= new Student();//向下转型
        Persons p1=new Persons();
        /*
        * 为了避免向下转型出错，Java提供了instanceof(运算符)操作符，
        * 可以先判断一个实例究竟是不是某种类型*/

//        System.out.println(p1 instanceof Person); // true
//        System.out.println(s instanceof Student); // false
        System.out.println(s.toString());
        System.out.println(p1 instanceof Persons);//true
        System.out.println(p1 instanceof Student);//false
        persons.run();
        p1.run();




        Object obj="hello";
        if(obj instanceof String s1){
            System.out.println(s1.toUpperCase());
        }
    }
}

        class Persons {
            protected String name;
            protected int age;
            public Persons(){

            }

            public Persons(String name, int age) {
                this.name = name;
                this.age = age;
            }
            public void run(){
                System.out.println("我会跑哦");
            }

        }

        class Student extends Persons {
            protected int score;

            public Student(){

            }
            public Student(String name, int age, int score) {
                super(name,age);
                this.score = score;
            }

            @Override
            public void run() {
                System.out.println("我跑的更快");//
            }
        }
